home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / free_user.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  3KB  |  124 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: free_user.c,v 1.47 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "opennap.h"
  10. #include "hashlist.h"
  11. #include "debug.h"
  12.  
  13. void
  14. free_user (USER * user)
  15. {
  16.     LIST   *list;
  17.     USERDB *db;
  18.     whowas_t *who;
  19.     ip_info_t *info;
  20.  
  21.     ASSERT (validate_user (user));
  22.  
  23.     if (ISUSER (user->con) && Servers && !user->con->killed)
  24.     {
  25.     /* local user, notify peers of this user's departure */
  26.     pass_message_args (user->con, MSG_CLIENT_QUIT, "%s", user->nick);
  27.     }
  28.  
  29.     /* remove this user from any channels they were on */
  30.     if (user->channels)
  31.     {
  32.     for (list = user->channels; list; list = list->next)
  33.     {
  34.         /* notify locally connected clients in the same channel that
  35.            this user has parted */
  36.         part_channel (list->data, user);
  37.     }
  38.     list_free (user->channels, 0);
  39.     }
  40.  
  41.     /* check the global hotlist for this user to see if anyone wants notice
  42.        of this user's departure */
  43.     for (list = hashlist_lookup (Hotlist, user->nick); list;
  44.      list = list->next)
  45.     {
  46.     ASSERT (validate_connection (list->data));
  47.     send_cmd (list->data, MSG_SERVER_USER_SIGNOFF, "%s", user->nick);
  48.     }
  49.  
  50.     ASSERT (Num_Files >= user->shared);
  51.     Num_Files -= user->shared;
  52.     ASSERT (Num_Gigs >= user->libsize);
  53.  
  54.     if (Num_Gigs < user->libsize)
  55.     {
  56.     log ("free_user: bad total lib size: Num_Gigs=%f user->libsize=%u",
  57.          Num_Gigs, user->libsize);
  58.     Num_Gigs = user->libsize;    /* prevent negative value */
  59.     }
  60.     Num_Gigs -= user->libsize;    /* this is in kB */
  61.  
  62. #ifndef ROUTING_ONLY
  63.     if (ISUSER (user->con))
  64.     {
  65.     if (user->shared > Local_Files)
  66.     {
  67.         log
  68.         ("free_user: local file count error, %s is sharing %d, more than %d",
  69.          user->nick, user->shared, Local_Files);
  70.         Local_Files = 0;
  71.     }
  72.     else
  73.         Local_Files -= user->shared;
  74.     }
  75. #endif /* !ROUTING_ONLY */
  76.  
  77.     /* record the log off time */
  78.     if ((db = hash_lookup (User_Db, user->nick)))
  79.     db->lastSeen = global.current_time;
  80.  
  81.     /* save info in the who-was table */
  82.     who = hash_lookup (Who_Was, user->nick);
  83.     if (!who)
  84.     {
  85.     who = CALLOC (1, sizeof (whowas_t));
  86.     if (!who)
  87.     {
  88.         OUTOFMEMORY ("free_user");
  89.         FREE (user->nick);
  90.     }
  91.     else
  92.     {
  93.         who->nick = user->nick;
  94.         hash_add (Who_Was, who->nick, who);
  95.     }
  96.     }
  97.     else
  98.     FREE (user->nick);
  99.     if (who)
  100.     {
  101.     who->ip = user->ip;
  102.     who->when = global.current_time;
  103.     who->server = user->server;
  104.     who->clientinfo = user->clientinfo;
  105.     }
  106.  
  107.     memset (user->pass, 0, strlen (user->pass));
  108.     FREE (user->pass);
  109.  
  110.     /* decrement the clone count */
  111.     info = hash_lookup (Clones, (void *) user->ip);
  112.     if (info->users <= 0)
  113.     {
  114.     log ("free_user: ERROR, info->users <= 0");
  115.     info->users = 0;
  116.     }
  117.     else
  118.     info->users--;
  119.  
  120.     /* NOTE: user->server is just a ref, not a malloc'd pointer */
  121.     memset (user, 0xff, sizeof (USER));    /* catch refs to bad memory */
  122.     FREE (user);
  123. }
  124.